package open.witype.filetiper.fragment.menu.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

import open.witype.filetiper.R;
import open.witype.filetiper.activity.home.interf.OnItemClickListener;
import open.witype.filetiper.model.FavoItemBeam;

/**
 * Created by Typer on 2015/6/1 0001.
 */
public class MenuRecyclerAdapter extends RecyclerView.Adapter<MenuViewHolder> {

    private List<FavoItemBeam> favos;

    private OnItemClickListener itemClickListener;

    public MenuRecyclerAdapter(List<FavoItemBeam> favos) {
        this.favos = favos;
    }

    public void setItemClickListener(OnItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }

    @Override
    public void onBindViewHolder(MenuViewHolder holder, final int position) {
        final FavoItemBeam itemBeam = favos.get(position);
        holder.menu_name.setText(itemBeam.getRemark());
        holder.menu_container.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (itemClickListener != null)
                    itemClickListener.onItemClickCallback(itemBeam,position);
            }
        });
        int type = getItemViewType(position);
        FavoType b = FavoType.values()[type];
        determineType(holder,b);
    }

    public void determineType(MenuViewHolder holder,FavoType type){
        switch (type){
            case LOCALHOST:

                break;
            case BAIDUNETDISK:
                holder.menu_img.setBackgroundResource(R.mipmap.ic_menu_cloud);
                break;
            case _360NETDISK:

                break;
            case RECENTLY:
                break;
            case DIR:
                determineAbbre(holder);
                break;
            case ROOT:
                holder.menu_img.setBackgroundResource(R.mipmap.ic_menu_dis);
                break;
            default:

                break;
        }
    }

    public void determineAbbre(MenuViewHolder holder){
        holder.menu_img_tip.setVisibility(View.VISIBLE);
    }

    @Override
    public MenuViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_behind_item,null);
        return new MenuViewHolder(view);
    }

    @Override
    public int getItemCount() {
        return favos.size();
    }

    @Override
    public int getItemViewType(int position) {
        FavoItemBeam itemBeam = favos.get(position);
        String _type = itemBeam.get_enum();
        int po;
        try {
            po = FavoType.fromString(_type);
        }catch (Exception e){
            e.printStackTrace();
            return FavoType.DIR.getSerial();
        }
        return po;
    }
}
